package com.wabbei.fenxiao.bak;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

import org.apache.commons.codec.digest.DigestUtils;

import com.wabbei.fenxiao.action.data;

public class refreshSession {
	public static void main(String[] args) {
		try {
			String appkey = data.appkey;
			String secret = data.secret;
			String refreshToken = "";
			String sessionkey = data.sessionKey1;

			Map<String, String> signParams = new TreeMap<String, String>();
			signParams.put("appkey", appkey);
			signParams.put("refresh_token", refreshToken);
			signParams.put("sessionkey", sessionkey);

			StringBuilder paramsString = new StringBuilder();
			Set<Entry<String, String>> paramsEntry = signParams.entrySet();
			for (Entry paramEntry : paramsEntry) {
				paramsString.append(paramEntry.getKey()).append(
						paramEntry.getValue());
			}
			String sign = DigestUtils.md5Hex(
					(paramsString.toString() + secret).getBytes("utf-8"))
					.toUpperCase();
			String signEncoder = URLEncoder.encode(sign, "utf-8");
			String appkeyEncoder = URLEncoder.encode(appkey, "utf-8");
			String refreshTokenEncoder = URLEncoder.encode(refreshToken,
					"utf-8");
			String sessionkeyEncoder = URLEncoder.encode(sessionkey, "utf-8");
			String freshUrl = "http://container.api.taobao.com/container/refresh?appkey="
					+ appkeyEncoder
					+ "&refresh_token="
					+ refreshTokenEncoder
					+ "&sessionkey="
					+ sessionkeyEncoder
					+ "&sign="
					+ signEncoder;
			System.out.println(freshUrl);
		} catch (UnsupportedEncodingException e) {
		}
	}
}